﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FrogEngine
{
	public class GraphVertex<K, V> : IGraphVertex<K, V>
	{
		public GraphVertex()
		{
			adjacentEdges = new List<IGraphEdge<K, V>>();
			adjacentVerts = new HashSet<IGraphVertex<K, V>>();
		}

		private K key;
		public K Key
		{
			get { return key; }
			set { key = value; }
		}

		private V val;
		public V Value
		{
			get { return val; }
			set { val = value; }
		}

		private HashSet<IGraphVertex<K, V>> adjacentVerts;
		public ISet<IGraphVertex<K, V>> AdjacentVertices
		{
			get { return adjacentVerts; }
		}

		private List<IGraphEdge<K, V>> adjacentEdges;
		public IList<IGraphEdge<K, V>> AdjacentEdges
		{
			get { return adjacentEdges; }
		}

		private bool visited;
		public bool Visited
		{
			get { return visited; }
			set { visited = value; }
		}

		public IGraphEdge<K, V> GetSharedEdge(IGraphVertex<K, V> otherVertex)
		{
			return adjacentEdges.Single(a => (a.V1 == this && a.V2 == otherVertex) || (a.V2 == this && a.V1 == otherVertex)); 
		}

		private IGraphVertex<K, V> predecessor;
		public IGraphVertex<K, V> Predecessor
		{
			get { return predecessor; }
			set { predecessor = value; }
		}

		private double pathCost;
		public double PathCost
		{
			get { return pathCost; }
			set { pathCost = value; }
		}
	}
}
